<template>
	<div class="toExamines">
		<div class="borders">
			<p>审核选择</p>
			<div style="margin: 10px 0;"></div>
			<el-radio v-model="radio" :label="14161001" @change="changeRadio">审核通过</el-radio>
      <el-radio v-model="radio" :label="14161002">审核驳回</el-radio>
		</div>
    <el-form :model="ruleForm" :rules="radio===14161002?rules:{}"  ref="ruleForm" label-width="0px" class="demo-ruleForm">
      <div class="borders2">
        <el-form-item prop="auditingPostil">
          <el-input
            type="textarea"
            autosize
            maxlength="32"
            placeholder="意见批注"
            v-model="ruleForm.auditingPostil">
          </el-input>
        </el-form-item>
      </div>
    </el-form>
		<div class="buttons">
			<el-button :disabled="ajaxDisabled" @click="toExamine" type="primary">审核</el-button>
    	<el-button @click="closeDialog">返回</el-button>
		</div>

	</div>
</template>

<script>
import { managerAudit } from '@/api/retail/salesmanage/managerverify';
export default {
	name: 'toExamines',
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    },
    financialOrManager:{}
  },
	data (){
		return {
			radio: null,
      ruleForm: {
        auditingPostil: ''
      },
      rules: {
        auditingPostil: [{ required: true, message: '请填写意见批注', trigger: 'blur' }]
      },
      ajaxDisabled: false
		}
  },
  mounted (){
    console.log(this.rowData)
  },
	methods: {
    changeRadio (val) {
      this.$refs['ruleForm'].clearValidate()
    },
		toExamine (){
      if(this.radio){
        let para = {
          soNoId: this.rowData.soNoId,
          recordVersion: this.rowData.recordVersion,
          auditingResult: this.radio,
          auditingPostil: this.ruleForm.auditingPostil,
          financialOrManager: this.financialOrManager
        };
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            this.toExamines(para)
          } else {
            this.$message.error('请填写意见批注!');
            return false;
          }
        });
      }else {
        this.$message.error('请进行审核选择!');
      }
		},
    async toExamines (row){
      this.ajaxDisabled = true
      let res = await managerAudit(row);
      console.log(res)
      if(res.resultCode == 200){
        this.$message({
          message: '审核成功',
          type: 'success'
        });
        this.$emit('clos2', false);
      }
      this.ajaxDisabled = false
    },
		closeDialog() { //弹框返回
      this.$emit('close', false);
    },

	}
}
</script>

<style scoped="scoped" lang="less">
.borders {
	font-size: @textSizeSecondary;
	margin: 15px 0;
	border: 1px solid @borderColorSecondary;
  padding: 10px;
}
.buttons{
  margin-top: 20px;
  text-align: center;
}
</style>
